import {createRouter, createWebHistory} from "vue-router";
import {unauthorized} from "@/net";

const router = createRouter({
    // @ts-ignore
    history:createWebHistory(import.meta.env.BASE_URL),
    routes:[
        {
            path: '/',
            name:'welcome',
            // @ts-ignore
            component:()=>import('@/views/WelcomeView.vue'),
            children:[
                {
                    path:'',
                    name:'welcome-login',
                    // @ts-ignore
                    component:()=>import ('@/views/welcome/LoginPage.vue')
                },
                {
                    path:'/register',
                    name:'welcome-register',
                    // @ts-ignore
                    component:()=>import ('@/views/welcome/RegisterPage.vue')
                },
                {
                    path:'/forget',
                    name:'welcome-forget',
                    // @ts-ignore
                    component:()=>import ('@/views/welcome/ForgetPage.vue')
                }
            ]
        },{
            path:'/index',
            name:'/index',
            // @ts-ignore
            component:()=>import('@/views/IndexView.vue')
        },{
            path: '/super',
            name: 'super',
            // @ts-ignore
            component:()=>import('@/Views/super/super.vue'),
            meta:{
                title:'超级管理员'
            },
            children:[
                {
                    path: '/superOut',
                    name: 'superOut',
                    // @ts-ignore
                    component: () => import('@/views/super/superOut.vue'),
                    meta:{
                        title:'出库'
                    }
                },
                {
                    path:'/LoginApp',
                    name:'LoginApp',
                    // @ts-ignore
                    component:()=>import('@/components/Super/RegisterApp.vue'),
                    meta:{
                        title:'管理层用户账号申请'
                    },
                },{
                    path: '/salesin',
                    name: 'salesin',
                    // @ts-ignore
                    component: () => import('../components/Super/salesin.vue'),
                    meta:{
                        title:'入库流水'
                    }
                },{
                    path: '/salesout',
                    name: 'salesout',
                    // @ts-ignore
                    component: () => import('../components/Super/salesout.vue'),
                    meta:{
                        title:'出库流水'
                    }
                },{
                    path: '/statistics',
                    name: 'statistics',
                    // @ts-ignore
                    component: () => import('../components/Super/statistics.vue'),
                    meta:{
                        title:'流水图'
                    }
                },{
                    path:'',
                    name:'homepage',
                    // @ts-ignore
                    component:()=>import('../views/super/homepage.vue')
                },{
                    path: '/inventory',
                    name: 'inventory2',
                    // @ts-ignore
                    component: () => import('../views/aside/inventory.vue'),
                    meta:{
                        title:'库存'
                    }
                },{
                    path:'/outmap',
                    name:'out-map',
                    // @ts-ignore
                    component:()=>import('@/components/Map/map.vue'),
                    meta:{
                        title:'地图路线查看'
                    },
                },{
                    path: '/superput',
                    name: 'superput',
                    // @ts-ignore
                    component: () => import('@/Views/super/superPut.vue'),
                    meta:{
                        title:'入库'
                    }
                }
            ]
        },
        {
            path: '/home',
            name: 'home1',
            // @ts-ignore
            component:()=>import('@/views/admin/home.vue'),
            meta:{
                title:'管理员'
            },
            children:[
                {
                    path: '/inventory',
                    name: 'inventory1',
                    // @ts-ignore
                    component: () => import('../views/aside/inventory.vue'),
                    meta:{
                        title:'库存'
                    }
                },
                {
                    path: '/put',
                    name: 'put',
                    // @ts-ignore
                    component: () => import('../views/aside/put.vue'),
                    meta:{
                        title:'入库'
                    }
                },
                {
                    path: '/out',
                    name: 'out',
                    // @ts-ignore
                    component: () => import('../views/admin/outOrder1.vue'),
                    meta:{
                        title:'出库'
                    }
                }/*,{
                    path: '/salesin',
                    name: 'salesin',
                    // @ts-ignore
                    component: () => import('../components/Super/salesin.vue'),
                    meta:{
                        title:'入库流水'
                    }
                },{
                    path: '/salesout',
                    name: 'salesout',
                    // @ts-ignore
                    component: () => import('../components/Super/salesout.vue'),
                    meta:{
                        title:'出库流水'
                    }
                },{
                    path: '/statistics',
                    name: 'statistics',
                    // @ts-ignore
                    component: () => import('../components/Super/statistics.vue'),
                    meta:{
                        title:'流水图'
                    }
                }*/
            ]
        },{
            path:'/customer',
            name:'customer',
            //@ts-ignore
            component:()=>import('@/Views/customer/customer.vue'),
            children:[
                {
                    path: '/inventory',
                    name: 'inventory',
                    // @ts-ignore
                    component: () => import('../views/aside/inventory.vue'),
                    meta:{
                        title:'库存'
                    }
                }
            ]
        }
    ]
})

//路由守卫
router.beforeEach((to,from,next)=>{
    //unauthorized :: false---存在用户
    const isUnauthorized=unauthorized()
    console.log(to.name)
    // @ts-ignore
    /*if(to.name.startsWith("welcome-")&&!isUnauthorized){
        // @ts-ignore
        next('/')
        // @ts-ignore
    }else*/ if(to.fullPath.startsWith('/index')&&isUnauthorized){
        next('/')
    }else{
        next()
    }
})

// @ts-ignore
export default router

/*
declare module '@/router' {
    import { Plugin } from 'vue';
    const route: Plugin;
    export default route;
}*/
